package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.WarehouseStyleDao;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Warehouse;
import com.woniuxy.entity.WarehouseStyle;
import com.woniuxy.service.WarehouseStyleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class WarehouseStyleServiceImpl implements WarehouseStyleService {
    @Resource
    WarehouseStyleDao warehouseStyleDao;
    @Override
    public ResponseEntity findAll() {
        return new ResponseEntity<>(200, "成功", warehouseStyleDao.findAll());
    }

    @Override
    public ResponseEntity findByName(int currentPage, int pageSize, String name) {
        PageHelper.startPage(currentPage,pageSize);
        List<WarehouseStyle> list=warehouseStyleDao.findByName(name);
        PageInfo<WarehouseStyle> pageInfo=PageInfo.of(list);
        return new ResponseEntity(200, "成功", list);
    }

    @Override
    public ResponseEntity findAll(int currentPage, int pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<WarehouseStyle> list=warehouseStyleDao.findAll();
        PageInfo<WarehouseStyle> pageInfo=PageInfo.of(list);
        return new ResponseEntity(200, "成功", pageInfo);
    }

    @Override
    public ResponseEntity addOne(WarehouseStyle warehouseStyle) {
        int index = warehouseStyleDao.addOne(warehouseStyle);
        if (index > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity deleteOne(String id) {
        int index = warehouseStyleDao.deleteOne(id);
        if (index > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity updateOne(WarehouseStyle warehouseStyle) {
        int index = warehouseStyleDao.updateOne(warehouseStyle);
        if (index > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity deleteSome(int[] id) {
        int index = warehouseStyleDao.deleteSome(id);
        if (index > 0) {
            return ResponseEntity.SUCCESS;
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity findByCode(String style_code) {
        WarehouseStyle warehouseStyle= warehouseStyleDao.findByCode(style_code);
        if (warehouseStyle!=null){
            return new ResponseEntity(200,"成功",warehouseStyle);
        }
        return ResponseEntity.Fail;
    }

    @Override
    public ResponseEntity findByUname(String style_name) {
        WarehouseStyle warehouseStyle = warehouseStyleDao.findByUname(style_name);
        if (warehouseStyle!=null){
            return new ResponseEntity(200,"成功",warehouseStyle);
        }
        return ResponseEntity.Fail;
    }

}
